<template>
  <!-- 套餐 -->
  <section>
    <el-form :inline="true" @submit.native.prevent="getData(-1)">
      <el-form-item>
        <el-input v-model="form.packageName" placeholder="套餐名称"></el-input>
      </el-form-item>
      <el-form-item>
        <deptSearch v-model="form.deptId"></deptSearch>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" native-type="submit" circle icon="el-icon-search"></el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="warning" @click="onBuy">购买套餐</el-button>
      </el-form-item>
    </el-form>
    <table class="table-box">
      <thead>
        <tr>
          <th>名称</th>
          <th>原价/元</th>
          <th>套餐价/元</th>
          <!-- <th>操作</th> -->
        </tr>
      </thead>
      <tbody>
        <tr v-for="(item,index) in tableList" :key="index">
          <td>
            <el-link type="primary" @click="onDetail(item)">{{item.packageName}}</el-link>
          </td>
          <td>￥{{item.costPrice}}</td>
          <td>￥{{item.packagePrice}}</td>
          <!-- <td style=" white-space:nowrap;">
            <el-link type="primary" @click="onBuy(item)">购买</el-link>
          </td> -->
        </tr>
      </tbody>
    </table>
    <div v-if="tableList.length == 0" style="color:#999;padding:10px 0;text-align:center;">
      <i class="iconfont iconwushuju" style="font-size:40px;"></i>
      <div>暂无数据</div>
    </div>
    <br />
    <pager v-model="pager" @change-pagenum="getData"></pager>
    <groupObjDetail v-model="dialogDetail" :curItem="curItem"></groupObjDetail>
    <checkPat v-model="dialogCheckPat" @success="onSuccess"></checkPat>
    <buyGroupDrawer v-model="dialogBuy" :patientId="patientId" @success="onPay"></buyGroupDrawer>
  </section>
</template>
<script>
export default {
  name: "groupObject",
  components: {
    groupObjDetail: () => import("./_com/groupObjDetail.vue"),
    checkPat: () => import("./_com/checkPat.vue"),
    buyGroupDrawer: () => import("@/pages/_com/buyGroupDrawer.vue"),
    deptSearch:()=>import("@/pages/_com/deptSearch.vue")
  },
  data() {
    return {
      dialogBuy: false,
      dialogCheckPat: false,
      dialogDetail: false,
      patientId: "",
      curItem: {},
      form: {
        packageName: "",
        status: 1,
        hpId: "",
        deptId:''
      },
      tableList: [],
      qxBtns: {},
      pager: { pageSize: 20, pageNum: 1, total: 0 }
    };
  },
  mounted() {
    const th = this;
    th.form.hpId = th.adminUser.hpId;
    th.getQX();
    th.getData();
  },
  methods: {
    onBuy() {
      const th = this;
      if (!th.qxBtns.buy) {
        th.$message.warning("暂无权限");
        return;
      }
      th.dialogCheckPat = true;
    },
    //选择患者之后
    onSuccess(patId) {
      const th = this;
      th.patientId = patId;
      th.dialogBuy = true;
    },
    //去支付
    onPay(obj) {
      const th = this;
      let j = {
        id: obj.orderId,
        type:2
      };
      th.$router.push({
        path: "/page/paychargeV2",
        query: th.getUrlToken(j)
      });
      th.addNavMenu("收费", "/page/chargeIndexV2");
    },
    onDetail(obj) {
      const th = this;
      th.curItem = obj;
      th.dialogDetail = true;
    },
    getData(type) {
      let th = this;
      if (type == -1) {
        th.pager.pageNum = 1;
        th.pager.total = 0;
      }
      let j = {};
      Object.assign(j, th.pager);
      Object.assign(j, th.form);
      th.showLoading();
      th.$api
        .findPackageProjectAll(j)
        .then(res => {
          if (res.executed) {
            th.tableList = res.dataBody.list;
            th.pager.total = res.dataBody.total;
          }
          th.showLoading(false);
        })
        .catch(res => {
          th.showLoading(false);
        });
    }
  }
};
</script> 